package cn.rongdao.jrkabao.util;

import android.content.Context;
import android.text.TextUtils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import cn.rongdao.jrkabao.BuildConfig;
import cn.rongdao.jrkabao.R;

/**
 * Created by jiangyongxing on 2017/7/4.
 * 描述：
 */

public class ShowUtils {

    public static String getShow1() {
        return BuildConfig.appKeygradle;
    }

    public static String getShow2(Context context) {
        return context.getResources().getString(R.string.appkeystring);
    }


    public static String getMd5(String key1, String key2) {
        return md5(TextUtils.concat(key1, getShow1(), key2).toString());
    }

    public static String md5(String string) {
        if (TextUtils.isEmpty(string)) {
            return "";
        }
        MessageDigest md5;
        try {
            md5 = MessageDigest.getInstance("MD5");
            byte[] bytes = md5.digest(string.getBytes());
            String result = "";
            for (byte b : bytes) {
                String temp = Integer.toHexString(b & 0xff);
                if (temp.length() == 1) {
                    temp = "0" + temp;
                }
                result += temp;
            }
            return result;
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return "";
    }
}
